from wxpyview.ui.component.common.basewidget import *

class Frame(Widget):
    def _getParentParam(self, meta_widget):
        # TODO: re-implementation
        return None
    
    def _setParams(self, meta_widget):
        dom = meta_widget.getDOM()
        if not dom:
            raise IOException
        
        self.params["parent"] = self._getParentParam(meta_widget)
        self.params["id"] = -1
        self.params["title"] = dom.getAttribute("title")
        self.params["pos"] = ComponentLibrary.getPosParam(dom)
        self.params["size"] = ComponentLibrary.getSizeParam(dom)
        #self.params["style"]
        self.params["name"] = dom.getAttribute("name")

        self.minWidth = ComponentLibrary.str2int(dom.getAttribute("minWidth"), -1)
        self.minHeight = ComponentLibrary.str2int(dom.getAttribute("minHeight"), -1)
    
    def create(self, meta_widget):
        self._setParams(meta_widget)

        params = self.params
        
        # template class for creating wx.Frame on the fly
        class FrameTemplate(wx.Frame):
            def __init__(self):
                wx.Frame.__init__(self, **params)
        
        frame_obj = FrameTemplate()
        frame_obj.__class__.__name__ = "Frame"
        
        frame_obj.SetMinSize((self.minWidth, self.minHeight))
        
        return frame_obj